home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Languages / Oberon⁄F™ 1.1 / Obx / Docu / Lines (.txt) < prev    next >
Encoding:
Oberon Document  |  1996-01-05  |  4.2 KB  |  46 lines  |  [oODC/obnF]

  1. Documents.StdDocumentDesc
  2. Documents.DocumentDesc
  3. Containers.ViewDesc
  4. Views.ViewDesc
  5. Stores.StoreDesc
  6. Documents.ModelDesc
  7. Containers.ModelDesc
  8. Models.ModelDesc
  9. Stores.ElemDesc
  10. TextViews.StdViewDesc
  11. TextViews.ViewDesc
  12. TextModels.StdModelDesc
  13. TextModels.ModelDesc
  14. TextModels.AttributesDesc
  15. Helvetica
  16. Helvetica
  17. Helvetica
  18. StdLinks.LinkDesc
  19. StdCmds.OpenDoc('Obx/Mod/Lines')
  20. Helvetica
  21. DevCommanders.StdViewDesc
  22. DevCommanders.ViewDesc
  23. Oberon by Example: ObxLines
  24. This example implements a view which allows to draw lines with the mouse. Beyond line entry, the only interaction with such a view is through the keyboard: some characters are interpreted as colors, e.g. typing in an "r" sets a view's foreground color (in which the lines are drawn) to red. These two operations don't constitute a graphics editor yet, but can serve as a sketch for a more useful implementation. Full undo/redo of the two operations is supported, however.
  25. The implementation of ObxLines is simple: there is a view, a model, and a line data structure. The model represents a view's graph, which consists of a linear list of lines. A line is described by its two end points (x0, y0) and (x1, y1). Each view has its own independent foreground color. There is an operation for the entry of a line (a model operation), and an operation for the change of a foreground color (a view operation).
  26. When a line is entered (or the entry is undone), its bounding box is restored. For this purpose, a suitable update message is defined.
  27. There are two interesting aspects about the ObxLines implementation:
  28. The contents of a graph, i.e. the linear list of lines, is immutable. This means that a line which has been inserted in a graph is never modified again. The list may become longer by having another line point at the existing line, but the existing line itself remains unchanged. For example, an undo operation merely changes the graph to show a shorter piece of its line list, redo shows a larger piece of it again.
  29. An immutable data structure has the nice property that it can be freely shared: copying can be implemented merely by letting another pointer point to the same data structure. This is used in the example below when copying the model.
  30. The second interesting feature of ObxLines is the way rubberbanding is implemented. Rubberbanding is the feedback given when drawing a new line, as long as the mouse button is held down. Procedure HandleCtrlMsg shows a typical implementation of such a mechanism: it consists of a polling loop, which repeatedly polls the mouse button's state. When the mouse has moved, the old rubberband line must be erased, and a new one must be drawn.
  31. Erasing the old rubberband line is done using a temporary buffer. Before entering the polling loop, the frame's visible area is saved in the frame's buffer (one buffer can be opened simultaneously per frame). In the polling loop, when the rubberband line must be erased, its bounding box is restored from the buffer. After the polling loop, the last rubberband line is erased the same way, except that the temporary buffer is disposed of simultaneously.
  32. ObxLines
  33. sources
  34.  "ObxLines.Deposit; StdCmds.Open"
  35. TextControllers.StdCtrlDesc
  36. TextControllers.ControllerDesc
  37. Containers.ControllerDesc
  38. Controllers.ControllerDesc
  39. TextRulers.StdRulerDesc
  40. TextRulers.RulerDesc
  41. TextRulers.StdStyleDesc
  42. TextRulers.StyleDesc
  43. TextRulers.AttributesDesc
  44. Helvetica
  45. Documents.ControllerDesc
  46.